#! /bin/sh

echo ""
echo "================================================================================"
echo "Script that generates the documentation related to the NetBee library"
echo "All the files will be placed in the "docs\\exports" and "docs\\internals" folder."
echo "The Microsoft CHM help file will be placed in "release\\netbee.chm" "
echo ""
echo "Script launch order:"
echo "  1. createbin.sh"
echo "  2. createdoc.sh"
echo "  3. createdevpack.sh"
echo "  4. createsrc.sh"
echo "================================================================================"
echo ""
echo ""
echo "======================================"
echo "Deleting existing NetBee documentation"
echo "======================================"
echo ""

# Remove the folder that will contain the NetBee website
#rm -rf release/website 2> /dev/null

# Remove folders containing the documentation generated by doxygen
#rm -rf docs/exports/*
#rm -rf docs/internals/*


echo ""
echo "=========================================="
echo "Creating NetBee documentation with doxygen"
echo "  (Note: doxygen must be in your PATH)"
echo "=========================================="
echo ""

#mkdir docs
#mkdir docs/exports
#mkdir docs/internal

cd doxygen

doxygen nbee.dox
doxygen nbee_internal.dox

doxygen nbprotodb.dox
doxygen nbprotodb_internal.dox

doxygen nbpflcompiler.dox
#doxygen nbpflcompiler_internal.dox

doxygen nbnetvm.dox
doxygen nbnetvm_internal.dox

doxygen nbsockutils.dox
doxygen nbsockutils_internal.dox


## Generate NetVM instruction set
awk -f nbnetvm_generateinstructionset.awk < ../src/nbnetvm/opcodes.txt > ../docs/exports/netvm_instructionset.xml

cd ../



echo ""
echo "======================================================"
echo "Copying standard web pages in the documentation folder"
echo "======================================================"
echo ""

mkdir -p ./release/website
cp -rf ./docs/* ./release/website 2> /dev/null


# Remove all SVN folders
cd release/website
find . -depth -name .svn -exec rm -rf {} \;
cd ../..



#if [ "`uname`" != "Linux" ]
#then
#	echo ""
#	echo "=============================================================================="
#	echo "Generating HTML Help files"
#	echo "WARNINGS:"
#	echo "  - this command works only in Windows (CHM files cannot be generated on UNIX)"
#	echo "  - HTML Help Compiler must be in 'C:\Program Files\HTML Help Workshop'"
#	echo "=============================================================================="
#	echo ""
#
#	cd release/website
#	"/cygdrive/c/Program Files/HTML Help Workshop/hhc" netbee.hhp
#
#	# Move the CHM to the root folder
#	mv nbee.chm ../.
#	rm -rfd netbee.hhp
#
#	cd ../..
#fi

# Create a ZIP file for the Source pack
cd ./release/website
zip -r ../nbdocs.zip *
cd ../..

